/**
 * @file clock_ui_final.c
 * @brief 最终时钟UI - 具有滚动数字动画效果，匹配HTML参考设计
 */

#include "lvgl/lvgl.h"
#include <time.h>
#include <stdio.h>
#include <stdlib.h>

/* 精确的颜色定义，匹配HTML参考设计 */
#define COLOR_HEADER_BG    lv_color_hex(0x7DD3C0)     /* 青绿色头部背景 */
#define COLOR_HEADER_TEXT  lv_color_hex(0x1F2937)     /* 头部深色文字 */
#define COLOR_MIDDLE_BG    lv_color_hex(0xF0F0F0)     /* 浅灰色中间背景 */
#define COLOR_TIME_RED     lv_color_hex(0xE74C3C)     /* 红色时间显示 */
#define COLOR_BOTTOM_BG    lv_color_hex(0x4A90E2)     /* 蓝色底部背景 */
#define COLOR_WHITE        lv_color_hex(0xFFFFFF)     /* 白色文字 */
#define COLOR_BLACK        lv_color_hex(0x000000)     /* 黑色阴影 */

/* UI界面对象 */
static lv_obj_t *main_screen;
static lv_obj_t *header_year;
static lv_obj_t *header_month;
static lv_obj_t *header_date;
static lv_obj_t *period_label;
static lv_obj_t *clock_icon;
static lv_obj_t *temp_value;
static lv_obj_t *day_label;
static lv_obj_t *humidity_value;
static lv_timer_t *time_timer;

/* 数字滚动动画容器 */
static lv_obj_t *hour_tens_container;
static lv_obj_t *hour_ones_container;
static lv_obj_t *minute_tens_container;
static lv_obj_t *minute_ones_container;
static lv_obj_t *second_tens_container;
static lv_obj_t *second_ones_container;

/* 数字滚动条 */
static lv_obj_t *hour_tens_strip;
static lv_obj_t *hour_ones_strip;
static lv_obj_t *minute_tens_strip;
static lv_obj_t *minute_ones_strip;
static lv_obj_t *second_tens_strip;
static lv_obj_t *second_ones_strip;

/* 动画跟踪变量 */
typedef struct {
    int virtual_pos;    /* 虚拟位置 */
    int last_value;     /* 上次数值 */
    int max_value;      /* 最大数值 */
} digit_state_t;

static digit_state_t digit_states[6] = {
    {0, -1, 2}, // 小时十位
    {0, -1, 9}, // 小时个位
    {0, -1, 5}, // 分钟十位
    {0, -1, 9}, // 分钟个位
    {0, -1, 5}, // 秒钟十位
    {0, -1, 9}  // 秒钟个位
};

/* 月份和星期名称 */
static const char* months[] = {
    "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE",
    "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"
};

static const char* days[] = {
    "SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY"
};

static const char* periods[] = {
    "NIGHT", "MORNING", "AFTERNOON", "EVENING"
};

/**
 * 创建可滚动的数字条，包含多次重复的数字序列
 */
static lv_obj_t* create_digit_strip(lv_obj_t *parent, int max_digit, const lv_font_t *font)
{
    lv_obj_t *strip = lv_obj_create(parent);
    lv_obj_set_size(strip, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
    lv_obj_set_style_bg_opa(strip, LV_OPA_TRANSP, 0);
    lv_obj_set_style_border_width(strip, 0, 0);
    lv_obj_set_style_pad_all(strip, 0, 0);
    lv_obj_set_flex_flow(strip, LV_FLEX_FLOW_COLUMN);
    lv_obj_set_flex_align(strip, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
    
    /* 创建3次数字序列重复，用于平滑滚动 */
    for (int rep = 0; rep < 3; rep++) {
        for (int i = 0; i <= max_digit; i++) {
            lv_obj_t *digit_label = lv_label_create(strip);
            char digit_text[2];
            sprintf(digit_text, "%d", i);
            lv_label_set_text(digit_label, digit_text);
            lv_obj_set_style_text_font(digit_label, font, 0);
            lv_obj_set_style_text_color(digit_label, COLOR_TIME_RED, 0);
            lv_obj_set_style_text_align(digit_label, LV_TEXT_ALIGN_CENTER, 0);
            lv_obj_set_style_pad_all(digit_label, 0, 0);
            
            /* 设置一致的高度用于数字对齐 */
            lv_obj_set_height(digit_label, 60);
            lv_obj_set_style_text_line_space(digit_label, 0, 0);
        }
    }
    
    return strip;
}

/**
 * 创建数字容器，隐藏溢出内容用于动画效果
 */
static lv_obj_t* create_digit_container(lv_obj_t *parent)
{
    lv_obj_t *container = lv_obj_create(parent);
    lv_obj_set_size(container, 50, 60);
    lv_obj_set_style_bg_opa(container, LV_OPA_TRANSP, 0);
    lv_obj_set_style_border_width(container, 0, 0);
    lv_obj_set_style_pad_all(container, 0, 0);
    lv_obj_set_style_clip_corner(container, true, 0);
    lv_obj_clear_flag(container, LV_OBJ_FLAG_OVERFLOW_VISIBLE);
    
    return container;
}

/**
 * 使用平滑滚动将数字动画到目标位置
 */
static void animate_digit_to_position(lv_obj_t *strip, int target_pos)
{
    lv_anim_t anim;
    lv_anim_init(&anim);
    lv_anim_set_var(&anim, strip);
    lv_anim_set_exec_cb(&anim, (lv_anim_exec_xcb_t)lv_obj_set_y);
    lv_anim_set_values(&anim, lv_obj_get_y(strip), -target_pos * 60);
    lv_anim_set_duration(&anim, 600);
    lv_anim_set_path_cb(&anim, lv_anim_path_ease_out);
    lv_anim_start(&anim);
}

/**
 * 定时器回调函数，用于重置数字条位置
 */
static void reset_strip_position_cb(lv_timer_t *timer)
{
    lv_obj_t *strip = (lv_obj_t*)lv_timer_get_user_data(timer);
    digit_state_t *state = (digit_state_t*)lv_obj_get_user_data(strip);
    int actual_pos = state->virtual_pos % (state->max_value + 1);
    state->virtual_pos = actual_pos + (state->max_value + 1);
    lv_obj_set_y(strip, -state->virtual_pos * 60);
    lv_timer_delete(timer);
}

/**
 * 使用平滑动画更新指定数字
 */
static void update_digit_animated(lv_obj_t *strip, digit_state_t *state, int new_value)
{
    if (state->last_value == -1) {
        /* 首次初始化 */
        state->virtual_pos = new_value + (state->max_value + 1);
        lv_obj_set_y(strip, -state->virtual_pos * 60);
        state->last_value = new_value;
        return;
    }
    
    if (new_value != state->last_value) {
        /* 计算下一个虚拟位置 */
        if (state->last_value == state->max_value && new_value == 0) {
            /* 环绕处理 - 继续向上滚动 */
            state->virtual_pos += 1;
        } else if (new_value > state->last_value) {
            /* 正常递增 */
            state->virtual_pos += (new_value - state->last_value);
        } else {
            /* 处理其他跳跃情况 */
            state->virtual_pos += (state->max_value + 1 - state->last_value + new_value);
        }
        
        /* 动画到新位置 */
        animate_digit_to_position(strip, state->virtual_pos);
        
        /* 如果位置过高则重置，防止溢出 */
        if (state->virtual_pos > (state->max_value + 1) * 2) {
            lv_timer_t *reset_timer = lv_timer_create(reset_strip_position_cb, 650, strip);
            lv_obj_set_user_data(strip, state);
        }
        
        state->last_value = new_value;
    }
}

/**
 * 使用动画更新所有时间数字
 */
static void update_time_animated(int hours, int minutes, int seconds)
{
    int h_tens = hours / 10;
    int h_ones = hours % 10;
    int m_tens = minutes / 10;
    int m_ones = minutes % 10;
    int s_tens = seconds / 10;
    int s_ones = seconds % 10;
    
    update_digit_animated(hour_tens_strip, &digit_states[0], h_tens);
    update_digit_animated(hour_ones_strip, &digit_states[1], h_ones);
    update_digit_animated(minute_tens_strip, &digit_states[2], m_tens);
    update_digit_animated(minute_ones_strip, &digit_states[3], m_ones);
    update_digit_animated(second_tens_strip, &digit_states[4], s_tens);
    update_digit_animated(second_ones_strip, &digit_states[5], s_ones);
}

/**
 * 使用真实系统时间更新时间显示
 */
static void update_time_cb(lv_timer_t *timer)
{
    time_t now;
    struct tm *tm_info;
    char temp_str[16];
    
    time(&now);
    tm_info = localtime(&now);
    
    /* 更新动画时间数字 */
    update_time_animated(tm_info->tm_hour, tm_info->tm_min, tm_info->tm_sec);
    
    /* 更新头部日期 - 日/月/年格式，如HTML */
    char day_str[8], year_str[8];
    sprintf(day_str, "%d", tm_info->tm_mday);
    sprintf(year_str, "%d", 1900 + tm_info->tm_year);
    
    lv_label_set_text(header_year, day_str);
    lv_label_set_text(header_month, months[tm_info->tm_mon]);
    lv_label_set_text(header_date, year_str);
    
    /* 更新时段 */
    int hour = tm_info->tm_hour;
    const char *period = "EVENING";
    if (hour >= 5 && hour < 12) {
        period = "MORNING";
    } else if (hour >= 12 && hour < 17) {
        period = "AFTERNOON";
    } else if (hour >= 17 && hour < 21) {
        period = "EVENING";
    } else {
        period = "NIGHT";
    }
    lv_label_set_text(period_label, period);
    
    /* 更新星期 */
    lv_label_set_text(day_label, days[tm_info->tm_wday]);
    
    /* 更新温度和湿度（模拟数据） */
    sprintf(temp_str, "23.6°C");
    lv_label_set_text(temp_value, temp_str);
    lv_label_set_text(humidity_value, "60%");
}

/**
 * 创建顶部头部，采用三部分布局
 */
static void create_header(lv_obj_t *parent)
{
    /* 头部容器 */
    lv_obj_t *header = lv_obj_create(parent);
    lv_obj_set_size(header, lv_pct(100), 60);
    lv_obj_align(header, LV_ALIGN_TOP_MID, 0, 0);
    lv_obj_set_style_bg_color(header, COLOR_HEADER_BG, 0);
    lv_obj_set_style_bg_opa(header, LV_OPA_COVER, 0);
    lv_obj_set_style_border_width(header, 0, 0);
    lv_obj_set_style_radius(header, 0, 0);
    lv_obj_set_style_pad_all(header, 25, 0);
    lv_obj_set_flex_flow(header, LV_FLEX_FLOW_ROW);
    lv_obj_set_flex_align(header, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
    
    /* 禁用头部的滚动和点击功能 */
    lv_obj_clear_flag(header, LV_OBJ_FLAG_SCROLLABLE);
    lv_obj_clear_flag(header, LV_OBJ_FLAG_CLICKABLE);
    
    /* 年份（左侧） */
    header_year = lv_label_create(header);
    lv_label_set_text(header_year, "21");
    lv_obj_set_style_text_font(header_year, &lv_font_montserrat_30, 0);
    lv_obj_set_style_text_color(header_year, COLOR_HEADER_TEXT, 0);
    lv_obj_set_style_text_align(header_year, LV_TEXT_ALIGN_LEFT, 0);
    /* 禁用年份标签的交互功能 */
    lv_obj_clear_flag(header_year, LV_OBJ_FLAG_CLICKABLE);
    
    /* 月份（中央） */
    header_month = lv_label_create(header);
    lv_label_set_text(header_month, "OCTOBER");
    lv_obj_set_style_text_font(header_month, &lv_font_montserrat_26, 0);
    lv_obj_set_style_text_color(header_month, COLOR_HEADER_TEXT, 0);
    lv_obj_set_style_text_align(header_month, LV_TEXT_ALIGN_CENTER, 0);
    lv_obj_set_style_text_letter_space(header_month, 3, 0);
    /* 禁用月份标签的交互功能 */
    lv_obj_clear_flag(header_month, LV_OBJ_FLAG_CLICKABLE);
    
    /* 日期（右侧） */
    header_date = lv_label_create(header);
    lv_label_set_text(header_date, "2024");
    lv_obj_set_style_text_font(header_date, &lv_font_montserrat_30, 0);
    lv_obj_set_style_text_color(header_date, COLOR_HEADER_TEXT, 0);
    lv_obj_set_style_text_align(header_date, LV_TEXT_ALIGN_RIGHT, 0);
    /* 禁用日期标签的交互功能 */
    lv_obj_clear_flag(header_date, LV_OBJ_FLAG_CLICKABLE);
}

/**
 * 创建主要时间显示区域，包含动画数字
 */
static void create_time_display(lv_obj_t *parent)
{
    /* 主内容区域 */
    lv_obj_t *main_content = lv_obj_create(parent);
    lv_obj_set_size(main_content, lv_pct(100), 200);
    lv_obj_align(main_content, LV_ALIGN_CENTER, 0, 0);
    lv_obj_set_style_bg_color(main_content, COLOR_MIDDLE_BG, 0);
    lv_obj_set_style_bg_opa(main_content, LV_OPA_COVER, 0);
    lv_obj_set_style_border_width(main_content, 0, 0);
    lv_obj_set_style_radius(main_content, 0, 0);
    lv_obj_set_style_pad_all(main_content, 15, 0);
    
    /* 禁用主内容的通用滚动功能 */
    lv_obj_clear_flag(main_content, LV_OBJ_FLAG_SCROLLABLE);
    lv_obj_clear_flag(main_content, LV_OBJ_FLAG_CLICKABLE);
    
    /* 时段显示 */
    period_label = lv_label_create(main_content);
    lv_label_set_text(period_label, "MORNING");
    lv_obj_set_style_text_font(period_label, &lv_font_montserrat_20, 0);
    lv_obj_set_style_text_color(period_label, COLOR_TIME_RED, 0);
    lv_obj_set_style_text_letter_space(period_label, 4, 0);
    lv_obj_align(period_label, LV_ALIGN_TOP_MID, 0, 15);
    /* 禁用时段标签的交互功能 */
    lv_obj_clear_flag(period_label, LV_OBJ_FLAG_CLICKABLE);
    
    /* 动画数字的时间容器 */
    lv_obj_t *time_container = lv_obj_create(main_content);
    lv_obj_set_size(time_container, LV_SIZE_CONTENT, 80);
    lv_obj_align(time_container, LV_ALIGN_CENTER, 0, 10);
    lv_obj_set_style_bg_opa(time_container, LV_OPA_TRANSP, 0);
    lv_obj_set_style_border_width(time_container, 0, 0);
    lv_obj_set_style_pad_all(time_container, 0, 0);
    lv_obj_set_flex_flow(time_container, LV_FLEX_FLOW_ROW);
    lv_obj_set_flex_align(time_container, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
    lv_obj_set_style_pad_gap(time_container, 5, 0);
    
    /* 禁用时间容器的滚动功能 - 动画仅通过程序控制 */
    lv_obj_clear_flag(time_container, LV_OBJ_FLAG_SCROLLABLE);
    lv_obj_clear_flag(time_container, LV_OBJ_FLAG_CLICKABLE);
    
    /* 创建动画数字容器 */
    hour_tens_container = create_digit_container(time_container);
    hour_tens_strip = create_digit_strip(hour_tens_container, 2, &lv_font_montserrat_42);
    
    hour_ones_container = create_digit_container(time_container);
    hour_ones_strip = create_digit_strip(hour_ones_container, 9, &lv_font_montserrat_42);
    
    /* 冒号分隔符 */
    lv_obj_t *colon1 = lv_label_create(time_container);
    lv_label_set_text(colon1, ":");
    lv_obj_set_style_text_font(colon1, &lv_font_montserrat_42, 0);
    lv_obj_set_style_text_color(colon1, COLOR_TIME_RED, 0);
    /* 禁用冒号的交互功能 */
    lv_obj_clear_flag(colon1, LV_OBJ_FLAG_CLICKABLE);
    
    minute_tens_container = create_digit_container(time_container);
    minute_tens_strip = create_digit_strip(minute_tens_container, 5, &lv_font_montserrat_42);
    
    minute_ones_container = create_digit_container(time_container);
    minute_ones_strip = create_digit_strip(minute_ones_container, 9, &lv_font_montserrat_42);
    
    /* 冒号分隔符 */
    lv_obj_t *colon2 = lv_label_create(time_container);
    lv_label_set_text(colon2, ":");
    lv_obj_set_style_text_font(colon2, &lv_font_montserrat_42, 0);
    lv_obj_set_style_text_color(colon2, COLOR_TIME_RED, 0);
    /* 禁用冒号的交互功能 */
    lv_obj_clear_flag(colon2, LV_OBJ_FLAG_CLICKABLE);
    
    /* 带图标的秒钟部分 */
    lv_obj_t *seconds_section = lv_obj_create(time_container);
    lv_obj_set_size(seconds_section, LV_SIZE_CONTENT, 80);
    lv_obj_set_style_bg_opa(seconds_section, LV_OPA_TRANSP, 0);
    lv_obj_set_style_border_width(seconds_section, 0, 0);
    lv_obj_set_style_pad_all(seconds_section, 0, 0);
    lv_obj_set_flex_flow(seconds_section, LV_FLEX_FLOW_COLUMN);
    lv_obj_set_flex_align(seconds_section, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
    lv_obj_set_style_pad_gap(seconds_section, 10, 0);
    /* 禁用秒钟部分的滚动功能 */
    lv_obj_clear_flag(seconds_section, LV_OBJ_FLAG_CLICKABLE);
    
    /* 秒钟上方的时钟图标 */
    clock_icon = lv_label_create(seconds_section);
    lv_label_set_text(clock_icon, LV_SYMBOL_REFRESH);
    lv_obj_set_style_text_font(clock_icon, &lv_font_montserrat_18, 0);
    lv_obj_set_style_text_color(clock_icon, COLOR_TIME_RED, 0);
    /* 禁用时钟图标的交互功能 */
    lv_obj_clear_flag(clock_icon, LV_OBJ_FLAG_CLICKABLE);
    
    /* 秒钟数字容器 */
    lv_obj_t *seconds_digits = lv_obj_create(seconds_section);
    lv_obj_set_size(seconds_digits, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
    lv_obj_set_style_bg_opa(seconds_digits, LV_OPA_TRANSP, 0);
    lv_obj_set_style_border_width(seconds_digits, 0, 0);
    lv_obj_set_style_pad_all(seconds_digits, 0, 0);
    lv_obj_set_flex_flow(seconds_digits, LV_FLEX_FLOW_ROW);
    lv_obj_set_flex_align(seconds_digits, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
    lv_obj_set_style_pad_gap(seconds_digits, 3, 0);
    /* 禁用秒钟数字的滚动功能 */
    lv_obj_clear_flag(seconds_digits, LV_OBJ_FLAG_CLICKABLE);
    
    second_tens_container = create_digit_container(seconds_digits);
    second_tens_strip = create_digit_strip(second_tens_container, 5, &lv_font_montserrat_36);
    
    second_ones_container = create_digit_container(seconds_digits);
    second_ones_strip = create_digit_strip(second_ones_container, 9, &lv_font_montserrat_36);
}

/**
 * 创建底部状态栏
 */
static void create_status_bar(lv_obj_t *parent)
{
    /* 状态栏容器 */
    lv_obj_t *status_bar = lv_obj_create(parent);
    lv_obj_set_size(status_bar, lv_pct(100), 60);
    lv_obj_align(status_bar, LV_ALIGN_BOTTOM_MID, 0, 0);
    lv_obj_set_style_bg_color(status_bar, COLOR_BOTTOM_BG, 0);
    lv_obj_set_style_bg_opa(status_bar, LV_OPA_COVER, 0);
    lv_obj_set_style_border_width(status_bar, 0, 0);
    lv_obj_set_style_radius(status_bar, 0, 0);
    lv_obj_set_style_pad_all(status_bar, 25, 0);
    lv_obj_set_flex_flow(status_bar, LV_FLEX_FLOW_ROW);
    lv_obj_set_flex_align(status_bar, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
    
    /* 禁用状态栏的滚动和点击功能 */
    lv_obj_clear_flag(status_bar, LV_OBJ_FLAG_CLICKABLE);
    
    /* 温度部分 */
    lv_obj_t *temp_section = lv_obj_create(status_bar);
    lv_obj_set_size(temp_section, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
    lv_obj_set_style_bg_opa(temp_section, LV_OPA_TRANSP, 0);
    lv_obj_set_style_border_width(temp_section, 0, 0);
    lv_obj_set_style_pad_all(temp_section, 0, 0);
    lv_obj_set_flex_flow(temp_section, LV_FLEX_FLOW_ROW);
    lv_obj_set_flex_align(temp_section, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
    lv_obj_set_style_pad_gap(temp_section, 8, 0);
    /* 禁用温度部分的交互功能 */
    lv_obj_clear_flag(temp_section, LV_OBJ_FLAG_CLICKABLE);
    
    /* 温度图标 */
    lv_obj_t *temp_icon = lv_label_create(temp_section);
    lv_label_set_text(temp_icon, LV_SYMBOL_SETTINGS);
    lv_obj_set_style_text_font(temp_icon, &lv_font_montserrat_16, 0);
    lv_obj_set_style_text_color(temp_icon, COLOR_WHITE, 0);
    /* 禁用温度图标的交互功能 */
    lv_obj_clear_flag(temp_icon, LV_OBJ_FLAG_CLICKABLE);
    
    /* 温度数值 */
    temp_value = lv_label_create(temp_section);
    lv_label_set_text(temp_value, "23.6°C");
    lv_obj_set_style_text_font(temp_value, &lv_font_montserrat_26, 0);
    lv_obj_set_style_text_color(temp_value, COLOR_WHITE, 0);
    /* 禁用温度数值的交互功能 */
    lv_obj_clear_flag(temp_value, LV_OBJ_FLAG_CLICKABLE);
    
    /* 日期部分（中央） */
    day_label = lv_label_create(status_bar);
    lv_label_set_text(day_label, "DONNERSTAG");
    lv_obj_set_style_text_font(day_label, &lv_font_montserrat_20, 0);
    lv_obj_set_style_text_color(day_label, COLOR_WHITE, 0);
    lv_obj_set_style_text_letter_space(day_label, 2, 0);
    /* 禁用日期标签的交互功能 */
    lv_obj_clear_flag(day_label, LV_OBJ_FLAG_CLICKABLE);
    
    /* 湿度部分 */
    lv_obj_t *humidity_section = lv_obj_create(status_bar);
    lv_obj_set_size(humidity_section, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
    lv_obj_set_style_bg_opa(humidity_section, LV_OPA_TRANSP, 0);
    lv_obj_set_style_border_width(humidity_section, 0, 0);
    lv_obj_set_style_pad_all(humidity_section, 0, 0);
    lv_obj_set_flex_flow(humidity_section, LV_FLEX_FLOW_ROW);
    lv_obj_set_flex_align(humidity_section, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
    lv_obj_set_style_pad_gap(humidity_section, 8, 0);
    /* 禁用湿度部分的交互功能 */
    lv_obj_clear_flag(humidity_section, LV_OBJ_FLAG_CLICKABLE);
    
    /* 湿度图标 */
    lv_obj_t *humidity_icon = lv_label_create(humidity_section);
    lv_label_set_text(humidity_icon, LV_SYMBOL_WIFI);
    lv_obj_set_style_text_font(humidity_icon, &lv_font_montserrat_14, 0);
    lv_obj_set_style_text_color(humidity_icon, COLOR_WHITE, 0);
    /* 禁用湿度图标的交互功能 */
    lv_obj_clear_flag(humidity_icon, LV_OBJ_FLAG_CLICKABLE);
    
    /* 湿度数值 - 直接显示60%，不需要额外的文字 */
    humidity_value = lv_label_create(humidity_section);
    lv_label_set_text(humidity_value, "60%");
    lv_obj_set_style_text_font(humidity_value, &lv_font_montserrat_26, 0);
    lv_obj_set_style_text_color(humidity_value, COLOR_WHITE, 0);
    /* 禁用湿度数值的交互功能 */
    lv_obj_clear_flag(humidity_value, LV_OBJ_FLAG_CLICKABLE);
}

/**
 * 初始化并显示带动画效果的最终时钟UI
 */
void clock_ui_final_show(void)
{
    /* 创建主屏幕 */
    main_screen = lv_obj_create(NULL);
    lv_obj_set_size(main_screen, 480, 320);  // 横屏 480x320
    lv_obj_set_style_bg_color(main_screen, COLOR_MIDDLE_BG, 0);
    lv_obj_set_style_bg_opa(main_screen, LV_OPA_COVER, 0);
    lv_obj_set_style_border_width(main_screen, 0, 0);
    lv_obj_set_style_radius(main_screen, 8, 0);
    lv_obj_set_style_pad_all(main_screen, 0, 0);
    
    /* 创建UI组件 */
    create_header(main_screen);
    create_time_display(main_screen);
    create_status_bar(main_screen);
    
    /* 加载屏幕 */
    lv_screen_load(main_screen);
    
    /* 启动时间更新定时器 */
    time_timer = lv_timer_create(update_time_cb, 1000, NULL);
    
    /* 初始时间更新 */
    update_time_cb(NULL);
}

/**
 * 清理资源
 */
void clock_ui_final_cleanup(void)
{
    if (time_timer) {
        lv_timer_delete(time_timer);
        time_timer = NULL;
    }
} 